package com.dtf.admin.menu.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.dtf.admin.menu.vo.SystemMenu;
import com.dtf.admin.staff.vo.SystemStaff;
import com.dtf.core.common.service.BaseService;

@Service
public class SystemMenuService extends BaseService{
	
	public List<Map<String, Object>> loadAllMenuBtn(Map param){
		String querySQl = 
				"select * from ("
						+ "SELECT a.menu_id id,a.parent_id pid,a.menu_name name,'menu' type from system_menu a order by a.sort_order) system_menu " + 
							"union " +
						"SELECT b.btn_id id,b.menu_id pid,b.btn_name name,'btn' type from system_button b ";
		List listParam = new ArrayList();
		return super.getJdbcTemplate().queryForList(querySQl,listParam.toArray());
	}
	
	public void deleteMenu(String menu_id){
		SystemMenu systemMenu = new SystemMenu();
		systemMenu.setMenu_id(menu_id);
		systemMenu = (SystemMenu) this.get(systemMenu);
		//删除按钮
		String deleteBtnSQL = "delete from system_button where menu_id in( " +
					"select b.menu_id from system_menu b where b.menu_path like ?)";
		
		List param = new ArrayList();
		param.add(systemMenu.getMenu_path()+"%");
		
		this.getJdbcTemplate().update(deleteBtnSQL, param.toArray());
		
		//删除菜单
		String sql = "delete from system_menu where menu_path like '"+systemMenu.getMenu_path()+"%'";
		
		super.getJdbcTemplate().update(sql);
	}
}
